<template>
	<!-- 新契约工作列表 -承保后調查 -->
	<div class="fillcontain">
		<!-- 查询条件 -->
		<div class="fastQuery">
			<el-row>
				<el-col :span="2" class="fastQuery_title"><i class="el-icon-tickets"></i><span> 查询条件</span></el-col>
				<el-col :span="10"></el-col>
				<el-col :span="4" class="moreCondition">
					<span v-if="!isShow" @click="showorhide">更多条件 <i class="el-icon-d-arrow-right"></i></span>
					<span v-if="isShow" @click="showorhide">收起 <i class="el-icon-d-arrow-left"></i></span>
				</el-col>
				<el-col :span="8"></el-col>
			</el-row>
		</div>
		<el-form v-show="isShow" :model="searchParams"  label-width="100px" class="search_container">
			<el-row>

				<el-col :span="6" class="common-box">
					<el-form-item label="调查人员" prop="acceptcde">
						<el-input v-model="searchParams.acceptcde" placeholder="调查人员" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="辅助人员" prop="assistant">
						<el-input v-model="searchParams.q_assistant" placeholder="辅助人员"  oninput="if(value.length>8) value=value.slice(0,8)"  clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="调查单位" prop="invcoycde">
						<el-select v-model="searchParams.invcoycde" placeholder="调查单位" clearable>
							<el-option v-for="item in invcoycdes" :key="item.id" :label="item.fullname" :value="item.id"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="理赔号" prop="clmnum">
						<el-input v-model="searchParams.clmnum" placeholder="理赔号" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="保单号" prop="chdrnum">
						<el-input v-model="searchParams.chdrnum" placeholder="保单号"  oninput="if(value.length>8) value=value.slice(0,8)" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="受理号" prop="busino">
						<el-input v-model="searchParams.busino" placeholder="受理号" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="交查日期（起）" prop="submitdteBegin">
						<el-date-picker v-model="searchParams.submitdteBegin" type="date" value-format="yyyy-MM-dd" format="yyyy-MM-dd"
							placeholder="选择日期" @change="clearTimeSetDefault">
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="交查日期（止)" prop="submitdteEnd">
						<el-date-picker v-model="searchParams.submitdteEnd" type="date" value-format="yyyy-MM-dd" format="yyyy-MM-dd"
							placeholder="选择日期"  @change="clearTimeSetDefault">
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="完成日期（起）" prop="invcompdteBegin">
						<el-date-picker v-model="searchParams.invcompdteBegin" type="date" value-format="yyyy-MM-dd" format="yyyy-MM-dd"
							placeholder="选择日期" @change="clearTimeSetDefault">
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="完成日期（止）" prop="invcompdteEnd">
						<el-date-picker v-model="searchParams.invcompdteEnd" type="date" value-format="yyyy-MM-dd" format="yyyy-MM-dd"
							placeholder="选择日期"  @change="clearTimeSetDefault">
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="客户号" prop="clntnum">
						<el-input v-model="searchParams.clntnum" placeholder="客户号" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="是否处理" prop="routeid">
						<el-select v-model="searchParams.routeid" placeholder="是否处理" clearable>
							<el-option v-for="item in ingats" :key="item.value" :label="item.name" :value="item.value"></el-option>
						</el-select>
				    </el-form-item>
				</el-col>
				<el-col :span="6" class="text_center">
					<el-button type="primary" icon="el-icon-search" @click="search()"></el-button>
					<el-button type="primary" plain  icon="el-icon-refresh" @click="resetSearch()"></el-button>
				</el-col>
			</el-row>
		</el-form>
		<div class="contain">
			<!-- 操作按钮 -->
			<el-row>
<!--				<el-col :span="24" class="pb15 pt5">-->
<!--					<el-button type="danger" style="margin-left: 10px;"  plain @click="lock()">加锁</el-button>-->
<!--					<el-button type="danger"  plain @click="unlock()">解锁</el-button>-->
<!--				</el-col>-->
			</el-row>
		<!-- 查询结果 -->
		<div class="table_container">
			<el-table ref ="multipleTable" v-loading="loading" :data="tableData" highlight-current-row header-cell-class-name="table-header-class" :row-style="rowStyle" style="width:100%">
				<el-table-column type="selection" width="55" :selectable="interceptVip"></el-table-column>
				<el-table-column property="nodeName" label="任务类型" align='center' sortable show-overflow-tooltip min-width="100"></el-table-column>
				<el-table-column min-width="80" property="BUSINO" label="受理号" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="80" property="CLMNUM" label="理赔号" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="100" property="CHDRNUM" label="保单号" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="100" property="INVSNO" label="调查序号" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="100" property="DEPOTNO" label="处理状态" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="120" property="FLAG07" label="是否阳性发现" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="120" property="CRTDATE03" label="阳性发现日期" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="100" property="SUBMITDTE" label="交查日期" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="120" property="SUBMITCDE" label="交查人员" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="100" property="ACCEPTDTE" label="受理日期" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="120" property="ACCEPTCDE" label="调查人员" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="120" property="SCANTIME" label="辅助人员" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="100" property="INVCOMPDTE" label="完成日期" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="80" property="BUSITYPE" label="提调类型" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="80" property="INVCOYCDE" label="调查单位" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="80" property="INVTYPCDE" label="调查类型" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="120" property="INVSITE" label="调查地点" align='center' show-overflow-tooltip></el-table-column>
				<el-table-column min-width="100" property="INVSTSCDE" label="任务状态" align='center' show-overflow-tooltip>
					<template slot-scope="scope">
						 {{taskStatus[scope.row.INVSTSCDE]}}
					</template>
				</el-table-column>
				<el-table-column property="taskChange" label="任务流转" align='center' show-overflow-tooltip min-width="100" >
					<template slot-scope="scope">
						<el-link type="primary" @click="showChange(scope.row.taskno)" :disabled="!interceptVip(scope.row, scope.index)">任务流转</el-link>
					</template>
				</el-table-column>
<!--				<el-table-column min-width="80" fixed="right" label="处理" align='center'>-->
<!--					<template slot-scope="scope">-->
<!--						<span class="operationIcon" :disabled="dis(scope.row.routeid)" @click="changeTask(scope.row.taskno,scope.row.routeid)">-->
<!--                            <i class="el-icon-edit"></i>-->
<!--                        </span>-->
<!--					</template>-->
<!--				</el-table-column>-->
			</el-table>
			<el-row>
				<el-col :span="24">
					<div class="pagination">
						<el-pagination
							background
							v-if='paginations.total > 0'
							:page-sizes="paginations.pageSizes"
							:page-size="paginations.pageSize"
							:layout="paginations.layout"
							:total="paginations.total"
							:current-page='paginations.pageIndex'
							@current-change='handleCurrentChange'
							@size-change='handleSizeChange'>
						</el-pagination>
					</div>
				</el-col>
			</el-row>
		</div>
		</div>
		<task-change-list  :business="'INAF'" :taskNo="changeTaskNo" :drawer="showChangeFlag" @close="hideChange"></task-change-list>
		</div>
</template>

<script>
	import constant from '@/utils/constant';
	import TaskConstants,{call} from "@/api/taskManager/common";
	import {getDocTypeMap, warnOutSty,getNodeMap,getInvcoycdes} from "@/api/taskCenter/taskCommon";
	import {lock,unlock} from "@/api/taskCenter/taskCommon";
	import  {
		isNotNumber
	} from "@/api/refund/RefundCommon";
	import TaskChangeList from "../taskChangeList";

	export default {
		components: {
			TaskChangeList,
		},
		data(){
			return {
				nodeMap: {},//节点对象
				loading:false,
				isShow:false,
				emptySearchParams:{},
				tableData:[],
				changeTaskNo: "",
				showChangeFlag: false,
				invcoycdes:[],
				searchParams:{
					routeid:'ingat_dcl',
					acceptcde:'',
					assistant:'',
					invcoycde:'',
					clmnum:'',
					chdrnum:'',
					busino:'',
					submitdteBegin:'',
					submitdteEnd:'',
					invcompdteBegin:'',
					invcompdteEnd:'',
					clntnum:'',
					pageNumber:'',
					pageSize:'',

				},
				ingats:[
					{name:"请选择",value:""},
					//异常任务 待处理
					{name:"待处理",value:"ingat_dcl"},
					//异常任务已处理;
					{name:"已处理",value:"ingat_end"},
				],
				taskStatus:{
					"P" :  "待交查",
					"D" :  "交查",
					"A" :  "已分派",
					"M" :  "受理",
					"L" :  "送审",
					"S" :  "签核",
					"C" :  "完成",
					"W" :  "待分配",
					"F" :  "复核",
					"B" :  "拟方案",
					"E" :  "确定"
				},
				//需要给分页组件传的信息
				paginations: {
					total: 0,        // 总数
					pageIndex: 1,  // 当前位于哪页
					pageSize: 20,   // 1页显示多少条
					pageSizes: [5, 10, 15, 20],  //每页显示多少条
					layout: "total, sizes, prev, pager, next, jumper"   // 翻页属性
				},
				isFirstEnter:false
			}
		},
		created() {
			this.emptySearchParams= JSON.parse(JSON.stringify(this.searchParams));
			// this.getList();

		},
		activated(){
			this.getList();
			document.onkeydown = (event)=>{
				var e = event || window.event || arguments.callee.caller.arguments[0];
				if (e && e.keyCode == 113) {
					this.getList();
				}
			};
		},
		mounted() {
			setTimeout(()=>{
				this.isFirstEnter=true;
			},100)
			getDocTypeMap().then(data => this.docTypeMap = data);
			getNodeMap().then(data => this.nodeMap = data);
			getInvcoycdes().then(data => this.invcoycdes = data);
		},
		methods: {
			rowStyle({ row, rowIndex}) {
				return warnOutSty(row,this.nodeMap);
			},
			showChange(taskNo) {
				this.changeTaskNo = taskNo;
				this.showChangeFlag = true;
			},
			hideChange() {
				this.changeTaskNo = '';
				this.showChangeFlag = false;
			},
			dis(routeid) {
				if ( routeid== 'ingat_dcl'){
					return false;
				}
				return true;
			},
			showorhide() {
				this.isShow = !this.isShow;
			},
			show() {
				this.$store.dispatch('loading/CHANGE_LOADING', true);
			},
			cancle() {
				this.$store.dispatch('loading/CHANGE_LOADING', false)
			},
			// 每页多少条切换
			handleSizeChange(pageSize) {
				this.paginations.pageSize = pageSize;
				this.getList();
			},
			/* 文件类型 */
			getDocType(value) {
				for (var key in this.docTypeMap){
					if (this.docTypeMap[key]["sdoctypeid"] && this.docTypeMap[key]["sdoctypeid"] == value){
						value = this.docTypeMap[key]["sdoctypnam"]
						break;
					}
				}
				return value;
			},
			// 上下分页
			handleCurrentChange(page) {
				this.paginations.pageIndex = page;
				this.getList();
			},
			// 清除查询条件
			resetSearch(){
				this.searchParams = JSON.parse(JSON.stringify(this.emptySearchParams));
			},
			search() {
				if(this.searchParams.chdrnum !="" ){
					if ( isNotNumber(this.searchParams.chdrnum) || this.searchParams.chdrnum.length !=8) {
						this.$message.error("请正确输入保单号！");
						return;
					}
				}
				if(this.searchParams.busino !="" && isNotNumber(this.searchParams.busino) ){
					this.$message.error("请正确输入受理号！");
					return;
				}
				if(this.searchParams.submitdteBegin && this.searchParams.submitdteEnd){
					let oDate1 = new Date(this.searchParams.submitdteBegin);
					let oDate2 = new Date(this.searchParams.submitdteEnd);
					if(oDate1.getTime() > oDate2.getTime()){
						this.$message.error("交查起始时间不能大于结束时间！");
						return;
					}
				}
				if(this.searchParams.invcompdteBegin && this.searchParams.invcompdteEnd){
					let oDate1 = new Date(this.searchParams.invcompdteBegin);
					let oDate2 = new Date(this.searchParams.invcompdteEnd);
					if(oDate1.getTime() > oDate2.getTime()){
						this.$message.error("完成起始时间不能大于结束时间！");
						return;
					}
				}
				this.getList();
			},
			//加锁
			lock() {
				this.$store.dispatch('loading/CHANGE_LOADING',true);
				let arr = [];
				this.$refs.multipleTable.selection.forEach(item => {
					arr.push(item.taskno);
				});
				if (arr.length <= 0) {
					this.$message.error("请选择任务！");
					this.$store.dispatch('loading/CHANGE_LOADING',false);
					return;
				}
				lock(arr).then(res => {
					this.$store.dispatch('loading/CHANGE_LOADING',false);
					if (res.resultCode == constant.SUCCESS) {
						this.getList();
					} else {
						this.$alert(res.resultMsg, '错误信息', {
							confirmButtonText: '确定',
							callback: action => {
								this.$message({
									type: 'error',
									message: `action: ${action}`
								});
							}
						});
					}
				}).catch(err => {
					this.$store.dispatch('loading/CHANGE_LOADING',false);
				})
			},
			//解锁
			unlock() {
				this.$store.dispatch('loading/CHANGE_LOADING',true);
				let arr = [];
				this.$refs.multipleTable.selection.forEach(item => {
					arr.push(item.taskno);
				});
				if (arr.length <= 0) {
					this.$message.error("请选择任务！");
					this.$store.dispatch('loading/CHANGE_LOADING',false);
					return;
				}
				unlock(arr).then(res => {
					this.$store.dispatch('loading/CHANGE_LOADING',false)
					if (res.resultCode == constant.SUCCESS) {
						this.getList();
					} else {
						this.$alert(res.resultMsg, '错误信息', {
							confirmButtonText: '确定',
							callback: action => {
								this.$message({
									type: 'error',
									message: `action: ${action}`
								});
							}
						});
					}
				}).catch(err => {
					this.$store.dispatch('loading/CHANGE_LOADING',false);
				})
			},
			clearTimeSetDefault(val) {
				if (val == null) {
					val = '';
				}
			},
			getList() {
				this.show();
				this.paginations.total = 0;
				this.tableData = [];
				this.searchParams.pageNumber = this.paginations.pageIndex;
				this.searchParams.pageSize = this.paginations.pageSize;
				call(TaskConstants.apis.queryInvestigationList,this.searchParams,"POST").then( res =>{
					if(res.resultCode == constant.SUCCESS && res.data && res.data.list.length){
						this.paginations.total = res.data.total;
						this.tableData = res.data.list;
						this.tableData.forEach(item => {
							item["nodeName"] = this.getNodeName(item.routeid);
						})
					} else {
						this.$message.error("无符合条件任务！");
					}
					this.cancle();
				}).catch( err =>{
					this.cancle();
				})
			},
			/* 任务处理 */
			changeTask(taskno,routeid){
				if (routeid == 'ingat_end') {
					this.$message.error("该承保后调查任务任务节点任务已被处理，无法继续处理！");
					return;
				}
				this.show();
				let condition = `?taskno=`+taskno+`&routeid=ingat_end`
				call(TaskConstants.apis['unNormalTaskChange']+condition,null,"post").then(res =>{
					this.cancle();
					if(res.resultCode == constant.SUCCESS ){
						this.$message({
							message: res.resultMsg,
							type: "success"
						});
						this.getList();
					} else {
						this.$message({
							message: res.dresultMsg,
							type: "error"
						});
					}
				}).catch(err =>{
					this.cancle();
				})
			},
			getNodeName(value) {
				if (this.nodeMap && this.nodeMap["INAF" + "_"+ value] && this.nodeMap["INAF" + "_"+ value].content)
					return this.nodeMap["INAF" + "_"+ value].content;
				else
					return value;
			},
      // vip权限拦截
      interceptVip(row, index) {
        let rowStr = JSON.stringify(row);
        if (rowStr.indexOf("*") > -1) {
          return false;
        }
        return true;
      },
		}
	}
</script>

<style lang="less" scoped>
    .fillcontain{
        padding-bottom: 0;
        .fastQuery {
            padding: 15px 20px 10px 20px;
            background: #fff;
            border-bottom: 1px solid #e1e1e1;
            .fastQuery_title {
                color: #666;
                padding: 6px 0px;
            }
            .fastQuery_item {
                margin: 0 10px;
            }
            .item_default {
                .el-button {
                    color: #409EFF !important;
                    border-color: #c6e2ff !important;
                    background-color: #ecf5ff !important;
                }

            }
            .moreCondition {
                color: #68a3fc;
                cursor: pointer;
                padding: 6px 0px;

                .el-icon-d-arrow-right {
                    transform: rotate(90deg);
                }

                .el-icon-d-arrow-left {
                    transform: rotate(-90deg);
                }
            }
        }
    }
    .contain{
        background: #fff;
        padding: 10px;
        margin-bottom: 20px;
    }
   .pagination{
       padding: 10px 20px;
       text-align: right;
   }
   .operationIcon{
        // padding: 12px;
        border:1px solid #e5e5e5;
        border-radius: 50%;
        width: 22px;
        height: 22px;
        display: inline-block;
        cursor: pointer;
        box-shadow:0 0 3px #f9f9f9;
   }
   .search_container{
       padding: 20px 20px 0 20px;
    //    border-top: 1px solid #e1e1e1;
   }
   .common-box{
        padding-bottom: 15px;
    }
    .common-lab{
        line-height:normal!important;
        text-align: right;
        .labelName{
            text-align: right;
        }
    }
</style>



